#pragma once
#include "CXcpObjectBase.h"
#include "NoBaseClass.h"
#include "CXcpObjectThreadSafeAddRefPolicy.h"
#include "HWTexture.h"


class HWFrameKeyedMutex :
	public CXcpObjectBase<NoBaseClass,CXcpObjectThreadSafeAddRefPolicy>
{

public: 
	static HRESULT Create(struct IPALOptimizedGraphicsDevice * pUIThreadDevice, struct IPALOptimizedGraphicsDevice * pCompositorThreadDevice, HWFrameKeyedMutex * * ppHWFrameKeyedMutex);
	HRESULT AddSubrectForRelease(HWTexture * pSubrectPendingRelease);
	void ReleasePendingSubrects();
	HRESULT LockOnUIThread();
	HRESULT UnlockOnUIThread();
	HRESULT LockOnCompositorThread();
	HRESULT UnlockOnCompositorThread();

private: 
	HWFrameKeyedMutex(struct IPALKeyedMutex * pKeyedMutex);
	virtual ~HWFrameKeyedMutex();
	struct IPALKeyedMutex * m_pKeyedMutex;
	xvector<xref_ptr<HWTexture> > m_subrectsPendingRelease; 
};